<template>
  <div>
    文章管理
    <input type="file" name="file" @change="changeFile" ref="file" />
    <el-button @click="submit">提交</el-button>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      file: ''
    }
  },
  created() {},
  mounted() {},
  methods: {
    async submit() {
      if (this.file === '') this.$message.warning('请上传文件')
      else {
        const formData = new FormData()
        formData.append('file', this.file)
        await axios
          .post('http://127.0.0.1:3008/upload', formData)
          .then(() => {
            this.$message.success('上传成功')
          })
          .catch(() => {
            this.$message.error('上传失败')
          })
      }
    },
    changeFile() {
      this.file = this.$refs.file.files[0]
    }
  }
}
</script>

<style scoped lang="less"></style>
